﻿

using Ccteg.Common;
using Ccteg.Common.QueryModels.DncPermission;

using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Reflection;

namespace Ccteg.DB
{
    /// <summary>
    /// 
    /// </summary>
    public class MySqlDbContext : DbContext
    {


        /// <summary>
        /// 
        /// </summary>
        /// <param name="options"></param>
        public MySqlDbContext(DbContextOptions<MySqlDbContext> options) : base(options)
        {

        }
        /// <summary>



        public DbSet<tsk_jobtask> tsk_jobtask { get; set; }
        /// <summary>
        /// 系统配置数据
        /// </summary>
        public DbSet<Management_data> Management_data { get; set; }

        /// <summary>
        /// 工程项目
        /// </summary>
        public DbSet<srb_main_project> Srb_Main_Project { get; set; }

        /// <summary>
        /// 托管煤矿
        /// </summary>
        public DbSet<srb_main_mine> Srb_Main_Mine { get; set; }

        /// <summary>
        /// 自有煤矿
        /// </summary>
        public DbSet<srb_main_mine_self> Srb_Main_Mine_Self { get; set; }


        /// <summary>
        /// 加工基地
        /// </summary>
        public DbSet<srb_main_processingbase> Srb_Main_Processingbase { get; set; }

        /// <summary>
        /// 法律法规
        /// </summary>
        public DbSet<law_law> Law_Law { get; set; }

        public DbSet<sfm_job> sfm_job { get; set; }

        /// <summary>
        /// 安全工作管理
        /// </summary>
        public DbSet<tar_tar> Tar_Tar { get; set; }


        /// <summary>
        /// 安全组织机构
        /// </summary>
        public DbSet<org_org> ORG_Org { get; set; }

        /// <summary>
        /// 安全文化
        /// </summary>
        public DbSet<Scl_Scl> SCL_Scl { get; set; }

        /// <summary>
        /// 安全会议
        /// </summary>
        public DbSet<Scf_Scf> SCF_Scf { get; set; }

        /// <summary>
        /// 企业信息
        /// </summary>

        public DbSet<ent_baseinfo> Ent_Baseinfo { get; set; }
        public DbSet  <ent_baseinfo_ent> Ent_baseinfo_Ent { get; set; } //跨库查询
        /// <summary>
        /// 安全风险业务清单
        /// </summary>
        public DbSet<srb_main_risk> srb_main_risk { get; set; }



        /// <summary>
        /// 安全风险业务措施
        /// </summary>
        public DbSet<srb_main_risk_measure> srb_main_risk_measure { get; set; }
        public DbSet<cctegaq_test> cctegaq_test { get; set; }

        /// <summary>
        /// 风险管控
        /// </summary>
        public DbSet<rsk_rsk> Rsk_Rsk { get; set; }

        /// <summary>
        /// 风险管控---管控措施
        /// </summary>
        public DbSet<rsk_measure> Rsk_Measure { get; set; }
 

        
        
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        { 
            //modelBuilder.Entity<Scl_Scl>(e => { e.HasQueryFilter(x => x.Deleted == false); });
            //modelBuilder.Entity<Scf_Scf>(e => { e.HasQueryFilter(x => x.Deleted == false); });
            modelBuilder.Entity<law_law>(e => { e.HasQueryFilter(x => x.Deleted == false); });
            //modelBuilder.Entity<srb_main_risk>(e => { e.HasQueryFilter(x => x.Deleted == false); });
            //modelBuilder.Entity<srb_main_risk_measure>(e => { e.HasQueryFilter(x => x.Deleted == false); });
            //modelBuilder.Entity<rsk_rsk>(e => { e.HasQueryFilter(x => x.Deleted == false); });
            //modelBuilder.Entity<rsk_measure>(e => { e.HasQueryFilter(x => x.Deleted == false); });
            modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly());
            base.OnModelCreating(modelBuilder);

        }
    }
}



//e.HasQueryFilter(x => !x.Deleted);
//modelBuilder.Entity<Scl_Scl>(e =>
//{
//    e.HasOne(x => x.ent_baseinfo_ent).WithOne(x => x.Scl_Scl_No).HasForeignKey<Scl_Scl>(x => x.CompanyNo);
//   // e.HasQueryFilter(x => !x.Deleted);
//});